<html xmlns:th="http://www.thymeleaf.org" xmlns="http://www.w3.org/1999/xhtml">
<div class="row subsystem-header">
    <div class="pull-left">
        <span>任务配置管理</span>
        <i id="h-group-task-group-jobKey" style="display: none;" th:text="${groupId}"></i>
    </div>
</div>
<div class="row subsystem-toolbar">
    <div style="height: 44px; line-height: 44px;display: inline;">
        <span style="height: 30px; line-height: 30px; margin-top: 7px;display: inline"
              class="pull-left">&nbsp;任务组描述 = <span th:text="${groupDesc}"></span></span>
    </div>

    <div id="h-dispatch-group-task-toolbar-listt" class="pull-right">
        <button onclick="DispatchGroupTaskObj.addTask()" class="btn btn-info btn-sm" title="新增配置任务">
            <span class="icon-plus"> 添加任务</span>
        </button>
        <button onclick="DispatchGroupTaskObj.delete()" class="btn btn-danger btn-sm" title="删除配置任务">
            <span class="icon-trash"> 删除</span>
        </button>
    </div>
</div>
<div class="row" style="margin-top:6px;">
    <div id="h-dispatch-group-task-table-info"
         class="col-sm-12 col-md-12 col-lg-12">
        <table id="h-dispatch-group-task-relation-table"
               data-toggle="table"
               data-striped="true"
               data-unique-id="taskId"
               data-url="/v1/dispatch/group/define/task"
               data-side-pagination="client"
               data-pagination="true"
               data-search="false">
            <thead>
            <tr>
                <th data-field="state" data-checkbox="true"></th>
                <th data-align="center" data-width="46px" data-formatter="DispatchGroupTaskObj.formatterindex">序号</th>
                <th data-field="jobKey" data-align="center" data-width="280px">JobKey</th>
                <th data-align="center" data-field="code_number">任务编码</th>
                <th data-align="left" data-field="task_desc">任务名称</th>
                <th data-align="center" data-field="task_type_desc">任务类型</th>
                <th data-align="center" data-formatter="DispatchGroupDefineObj.formatterTask">操作</th>
            </tr>
            </thead>
        </table>
    </div>
</div>

<script type="text/javascript">
    $(document).ready(function () {
        var hwindow = document.documentElement.clientHeight;
        var groupId = $("#h-group-task-group-jobKey").html();
        $("#h-dispatch-group-task-relation-table").bootstrapTable({
            height: hwindow - 130,
            queryParams: function (params) {
                params.group_id = groupId;
                return params;
            }
        });

        $("#h-dispatch-group-task-button-list").height(hwindow - 130);
        $("#h-dispatch-group-task-dependency-info").height(hwindow - 130);
    });

    var DispatchGroupTaskObj = {
        formatterindex: function (value, row, index) {
            return index + 1;
        },
        addTask: function () {
            var groupId = $("#h-group-task-group-jobKey").html();
            DispatchGroupDefineObj.addTask(groupId);
        },
        refresh: function () {
            $("#h-dispatch-group-task-relation-table").bootstrapTable('refresh');
        },
        delete: function () {
            var rows = $("#h-dispatch-group-task-relation-table").bootstrapTable('getSelections');
            var arr = new Array();
            $(rows).each(function (index, element) {
                var e = {};
                e.jobKey = element.jobKey;
                arr.push(e);
            });

            $.HAjaxRequest({
                url: "/v1/dispatch/group/define/task/list/delete",
                type: "POST",
                data: {JSON: JSON.stringify(arr)},
                success: function () {
                    $.Notify({
                        message: "删除任务组中配置任务成功",
                        type: "success",
                    });
                    DispatchGroupTaskObj.refresh();
                }
            });
        },
    }
</script>

<script id="h-dispatch-group-task-dependency-src" type="text/html">
    <table id="h-dispatch-group-task-dependency-table"
           data-toggle="table"
           data-striped="true"
           data-unique-id="uuid"
           data-url="/v1/dispatch/group/define/task/dependency"
           data-side-pagination="client"
           data-pagination="false"
           data-search="false">
        <thead>
        <tr>
            <th data-align="center" data-width="46px" data-formatter="DispatchGroupTaskObj.formatterindex">序号</th>
            <th data-align="center" data-width="280px" data-field="upJobKey">上级JobKey</th>
            <th data-align="center" data-field="code_number">任务编码</th>
            <th data-align="left" data-field="task_desc">任务名称</th>
            <th data-align="center" data-formatter="DispatchGroupDefineObj.formatterDependency">操作</th>
        </tr>
        </thead>
    </table>
</script>
</html>
